package cn.lanqiao.blog.service.impl;


import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.lanqiao.blog.dao.MessageMapper;
import cn.lanqiao.blog.vo.MessageVO;
import cn.lanqiao.blog.service.MessageService;

@Service
public class MessageServiceImpl implements MessageService{

	@Autowired
	private MessageMapper messageMapper;

	@Override
	public List<MessageVO> getTalkList(Integer userId,Integer withUserId) {
		return messageMapper.getTalkMessages(userId, withUserId);		
	}
	//获取留言列表
	@Override
	public List<MessageVO> getMessageList(Integer userId) {
		return messageMapper.getMessageList(userId);
	}
	//添加留言
	@Override
	public int saveMessage(MessageVO message) {
		//保证发送表和接受表时间相同
		message.setTime(new Date());
		//存储在接收表
		int n = messageMapper.saveAcceptMessage(message);
		//存储在发送表
		int m = messageMapper.saveSendMessage(message);
		return m + n;
	}
	//清空聊天列表
	@Override
	public int deleteMessage(Integer userId,Integer withUserId) {
		//清除缓存
		//redisTemplate.delete("talk");
		//删除接收表数据
		int m = messageMapper.deleteAcceptMessage(userId, withUserId);
		//删除发送表数据
		int n = messageMapper.deleteSendMessage(userId, withUserId);
		return m + n;
	}
}
